// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
// import fastClick from 'fastclick'
// fastClick.attach(document.body)

import 'lib-flexible'
// import { Upload,Icon as IIcon} from 'iview'
// import 'iview/dist/styles/iview.css'
// Vue.component('Upload',Upload)
// Vue.component('IIcon',IIcon)
import {MessageBox} from 'mint-ui';
import 'mint-ui/lib/style.css'
// Vue.use(mint);
import API from '@/api'
Vue.prototype.API = API

import  { Confirm } from 'vux'
Vue.use('confirm',Confirm)

import {
  Cell,
  CellGroup,
  AddressList,
  Icon,
  Search,
  Checkbox,
  CheckboxGroup,
  Button,
  Stepper,
  AddressEdit,
  Area,
  Toast,
  GoodsAction,
  GoodsActionBigBtn,
  GoodsActionMiniBtn,
  Lazyload,
  Tab,
  Tabs,
  Rate,
  RadioGroup,
  Radio,
  Popup,
  Uploader,
  Dialog,
  Swipe,
  SwipeItem
} from 'vant'
Vue.use(Cell)
  .use(CellGroup)
  .use(AddressList)
  .use(Icon)
  .use(Search)
  .use(Checkbox)
  .use(CheckboxGroup)
  .use(Button)
  .use(Stepper)
  .use(AddressEdit)
  .use(Area)
  .use(Toast)
  .use(GoodsAction)
  .use(GoodsActionBigBtn)
  .use(GoodsActionMiniBtn)
  .use(Lazyload)
  .use(Tab)
  .use(Tabs)
  .use(Rate)
  .use(RadioGroup)
  .use(Radio)
  .use(Popup)
  .use(Uploader)
  .use(Dialog)
  .use(AddressEdit)
  .use(Swipe).use(SwipeItem)
  ;

Vue.config.productionTip = false
/* eslint-disable no-new */
import VueWechatTitle from 'vue-wechat-title'
Vue.use(VueWechatTitle)

router.beforeEach((to,from,next)=>{
  console.log('to',to)
  console.log('from',from)
  if(to.path === '/login' || to.path === '/bindphonenum' || to.path === '/signup' || to.path === '/forgetpwd'){
    next()
    return 
  }
  if(!localStorage.getItem('token') && to.meta.isNeedLogin){
    // next({path:'/login'})
    // return
    MessageBox({
      title:'温馨提示',
      message:'您还没有登录,先去登录吧~',
      showCancelButton:true,
      confirmButtonText:'登录',
      cancelButtonText:'取消'
    }).then(action => {
      if(action == 'confirm'){
        console.log(action)
        next({path:'/login'})
        return
      }else{
        console.log(action)
        return
      }
    })
    // Dialog.confirm({
    //   message:'您还没有登录,先去登录吧~'
    // }).then(()=>{
    //   console.log('queding')
    //   next({path:'/login'})
    //   return
    // }).catch(()=>{
    //   console.log('quxiao')
    //   // next({path:'/profile'})
    //   return
    // })
    return
  }
  next()
})

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

// router.beforeEach((to,from,next)=>{
//   // 获取用户登录成功后存储的登录标志
//   let getFlag = localStorage.getItem("Flag");

//   if(getFlag === 'isLogin'){ //已登录
//     store.state.isLogin = true
//     next()

//     // 如果已登录 还想进入登录注册界面
//     if(!to.meta.isLogin){
//       // Vue.$dialog.alert({
//       //   message: '请先退出登录'
//       // })
//       next({
//         path:'/msite'
//       })
//     }
//   }else{ //未登录
//     if(to.meta.isLogin){
//       next({
//         path:'/login'
//       })
//       // Vue.$dialog.alert({
//       //   message: '请先登录'
//       // })
//     }else{
//       next()
//     }
//   }
// })
// router.afterEach(route=>{
//   window.scroll(0,0)
// })